package 剑指offer.合并两个排序的链表_16;



public class Main {
    public ListNode Merge(ListNode list1,ListNode list2) {
        ListNode res = null;
        ListNode head=new ListNode(-1);
        head.next=null;
        res = head;
        while(list1 != null || list2 != null){
        	if(list1 != null && list2 != null){
        		if(list1.val >= list2.val){
        			head.next = list2;
        			list2 = list2.next;
        		}else{
        			head.next = list1;
        			list1 = list1.next;
        		}
        	}else if(list2 == null){
    				head.next = list1;
    				list1 = list1.next;
        	}else{
    				head.next = list2;
    				list2 = list2.next;
        	}
        	head = head.next;
    	}
        return res.next;
    }
}
